import { reactive } from "vue";
import { getAllCompanyApi } from "@/api/managementCenter/departmentPersonnel";
import { getListApi } from "@/api/configCenter/outBoundAgent";
import { getAllAccountTreeApi } from "@/api/financialManagement/receivable/waterVerification";
import { TreeSelect } from "ant-design-vue";
const SHOW_CHILD = TreeSelect.SHOW_CHILD;
export const searchItemList: Array<SuperSearch.SearchItem> = [
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "代理商",
    keyName: "agentIdList",
    optionsRequest: getListApi,
    optReqParams: { status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.records || [];
      }
    },
    optConfig: {
      label: "name",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  }),
  reactive<SuperSearch.SearchItem>({
    type: "cascader",
    label: "付款账户",
    keyName: "payAccountIdList",
    optConfig: {
      label: "name",
      value: "id",
      children: "deptAccounts"
    },
    optionsRequest: getAllAccountTreeApi,
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.map((t: any) => {
          return {
            name: t.deptName,
            id: t.deptId,
            ...t
          };
        });
      }
    },
    attrs: {
      multiple: true,
      showCheckedStrategy: SHOW_CHILD
    },
    options: []
  }),
  {
    type: "datetimerange",
    label: "付款时间",
    keyName: "payTimeList"
  },
  {
    type: "datetimerange",
    label: "添加时间",
    keyName: "createTimeList"
  },
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "经营单位",
    keyName: "companyIdList",
    optionsRequest: getAllCompanyApi,
    optReqParams: { status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data || [];
      }
    },
    optConfig: {
      label: "name",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  })
];

export const tableColumnMap: Base.GeneraDataType<Array<SuperTable.TableCoulmnItem | SuperTable.NestTableColumnItem>> = {
  1: [
    {
      type: "checkbox",
      field: "checkbox",
      minWidth: "50"
    },
    {
      field: "agent",
      title: "代理商",
      minWidth: "150",
      sortable: true
    },
    {
      field: "payAccount",
      title: "付款账户",
      minWidth: "150",
      sortable: true
    },
    {
      field: "companyName",
      title: "经营单位",
      minWidth: "120",
      sortable: true
    },
    {
      field: "payAmount",
      title: "付款金额",
      minWidth: "120"
    },
    {
      field: "unWriteAmount",
      title: "未核销金额",
      minWidth: "120"
    },
    {
      field: "writeAmount",
      title: "已核销金额",
      minWidth: "120"
    },
    {
      field: "payTime",
      title: "付款时间",
      minWidth: "135",
      formatter: "formatDate"
    },
    {
      field: "remark",
      title: "付款备注",
      minWidth: "90"
    },
    {
      field: "serialNumber",
      title: "流水号",
      minWidth: "90"
    },
    {
      field: "createName",
      title: "添加人",
      minWidth: "90"
    },
    {
      field: "createTime",
      title: "添加时间",
      minWidth: "135",
      formatter: "formatDate"
    },
    {
      field: "action",
      title: "操作",
      minWidth: "140",
      renderSlot: "action"
    }
  ],
  2: [
    {
      type: "checkbox",
      field: "checkbox",
      minWidth: "50"
    },
    {
      field: "agent",
      title: "代理商",
      minWidth: "120",
      sortable: true
    },
    {
      field: "payAccount",
      title: "付款账户",
      minWidth: "150",
      sortable: true
    },
    {
      field: "companyName",
      title: "经营单位",
      minWidth: "120",
      sortable: true
    },
    {
      field: "payAmount",
      title: "付款金额",
      minWidth: "90"
    },
    {
      field: "unWriteAmount",
      title: "未核销金额",
      minWidth: "90"
    },
    {
      field: "writeAmount",
      title: "已核销金额",
      minWidth: "90"
    },
    {
      field: "payTime",
      title: "付款时间",
      minWidth: "135",
      formatter: "formatDate"
    },
    {
      field: "remark",
      title: "付款备注",
      minWidth: "90"
    },
    {
      field: "serialNumber",
      title: "流水号",
      minWidth: "90"
    },
    {
      field: "createName",
      title: "添加人",
      minWidth: "90"
    },
    {
      field: "createTime",
      title: "添加时间",
      minWidth: "135",
      formatter: "formatDate"
    },
    {
      field: "updateName",
      title: "核销人",
      minWidth: "90"
    },
    {
      field: "updateTime",
      title: "核销时间",
      minWidth: "135",
      formatter: "formatDate"
    }
  ]
};
